package com.slipper.bpmn.controller;

import com.slipper.constants.Constants;
import com.slipper.system.flow.bo.FlowBO;
import com.slipper.system.flow.bo.FlowSignatureBO;
import com.slipper.system.flow.service.FlowService;
import com.slipper.system.flow.service.FlowSignatureService;
import com.slipper.util.ResultUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/flow")
public class FlowApiController {
    @Resource
    private FlowService flowService;
    @Resource
    private FlowSignatureService flowSignatureService;

    @PostMapping("/flow/queryBy")
    public String queryBy(@RequestBody FlowBO bo) {
        return ResultUtil.successResult(flowService.queryBy(bo.getId()));
    }

    @PostMapping("/signature/queryList")
    public String signatureList() {
        FlowSignatureBO bo = new FlowSignatureBO();
        bo.setEmployeeId(Constants.getCurrentUserId());
        return ResultUtil.successResult(flowSignatureService.queryList(bo));
    }

    @PostMapping("/signature/default")
    public String signatureDefault(@RequestBody FlowSignatureBO bo) {
        bo.setEmployeeId(Constants.getCurrentUserId());
        bo.setUpdateId(bo.getEmployeeId());
        return ResultUtil.successResult(flowSignatureService.saveDefault(bo));
    }

    @PostMapping("/signature/save")
    public String signatureSave(@RequestBody FlowSignatureBO bo) {
        bo.setEmployeeId(Constants.getCurrentUserId());
        bo.setUpdateId(bo.getEmployeeId());
        bo.setCreateId(bo.getEmployeeId());
        return ResultUtil.saveResult(flowSignatureService.save(bo), bo);
    }

    @PostMapping("/signature/delete")
    public String signatureDelete(@RequestBody FlowSignatureBO bo) {
        return ResultUtil.deleteResult(flowSignatureService.delete(bo));
    }
}
